package com.example.jiaju.ui;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.jiaju.R;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

/**
 * 论坛
 *     - 家具  FurnitureFragment
 *     - 装修  DecorationFragment
 *     - 楼盘  BuildingFragment
 */
public class ForumFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View  view=inflater.inflate(R.layout.fragment_forum, container, false);

        TabLayout forum_tab=view.findViewById(R.id.forum_tab);
        ViewPager2 forum_view=view.findViewById(R.id.forum_view);

        forum_view.setAdapter(new FragmentStateAdapter(this) {
            @Override
            public int getItemCount() {
                return 2;
            }

            @NonNull
            @Override
            public Fragment createFragment(int position) {
                switch (position){
                    case 0:return new BuildingFragment();
//                    case 1:return new DecorationFragment();
                    default:return new FurnitureFragment();
                }
            }

        });

        new TabLayoutMediator(forum_tab,forum_view,(tab, position) -> {
            switch (position){
                case 0:tab.setText("楼盘");break;
//                case 1:tab.setText("装修");break;
                default:tab.setText("家具");break;
            }

        }).attach();

        return view;
    }
}